package com.dingshang.dsapp.controller;

import com.dingshang.dsapp.dto.ResponseDTO;
import com.dingshang.dsapp.exception.BizException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.ExceptionHandler;

public abstract class BaseController {

    protected static Logger logger = LoggerFactory.getLogger(BaseController.class);

    @Value("${file.image.path}")
    protected String filePath;

    @Value("${file.image.url}")
    protected String fileUrl;

    @ExceptionHandler(BizException.class)
    public ResponseDTO bizExceptionProcess(BizException be) {
        logger.error(be.getMessage(), be);
        return ResponseDTO.fail(be.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public ResponseDTO exceptionProcess(Exception e) {
        logger.error(e.getMessage(), e);
        return ResponseDTO.fail(e.getMessage());
    }

}
